home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0010_DELPHI Does DOS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  9.8 KB  |  263 lines

  1.  
  2. Instructions for preparing DELPHI to compile a DOS EXE with DCC.EXE
  3.  
  4. Requirements:
  5.   1) BP7 Runtime library source
  6.   2) Delphi VCL source
  7.   3) TASM.EXE
  8.   4) The new DLIB.EXE (available from CompuServe DELPHI forum)
  9.  
  10. Assumptions:
  11.   1) BP7 RTL is in \BP\RTL
  12.   2) Delphi VCL is in \DELPHI\SOURCE
  13.   3) \DELPHI\BIN is in your path as well as TASM.EXE
  14.  
  15. Copy from \BP\RTL\SYS to \DELPHI\SOURCE\RTL\SYS (all are .ASM):
  16.   MAIN, PARS, LAST, HEAP, F87H, EI87, EI86, DLIB, DAPP
  17.   (* note ERRC that was in this list has been removed - it should
  18.      not be copied over or exception handling will not work *)
  19.  
  20. -- DOS Real Mode ----------------------------------------------------------
  21.   Objective: create a TURBO.TPL with units compiled under DELPHI
  22.  
  23. 1) The first and main requirement is to get a SYSTEM.TPU for DOS mode.
  24. This will take some work because Delphi VCL source does not include
  25. MAIN.ASM which is required for compiling SYSTEM.PAS in DOS mode.  
  26. Some things need to be removed from MAIN.ASM because they now exist 
  27. in EXIT.ASM:
  28.   - remove HaltTurbo, HaltError, Terminate, PrintString from the PUBLIC
  29.     section.
  30.   - remove the procedure code for the above procedures.  (HaltError
  31.     starts in around line 210 or so and HaltTurbo starts around 230
  32.     or so.  PrintString ends around 395 +/- a few.)
  33.   - up at the top in Externals after "ASSUME  CS:CODE,DS:DATA" add 
  34.     another "EXTRN HaltError:NEAR,HaltTurbo:NEAR"
  35.   - down in "Int3FHandler" remove "SHORT" from "JMP SHORT HaltError"
  36.   - after "MOV AX,200" in Int00Handler add "JMP HaltError"
  37.   - after "MOV AX,255" in Int23Handler add "JMP HaltTurbo"
  38.  
  39. 2) Create OBJ from ASM: In \DELPHI\SOURCE\RTL\SYS type 
  40.      TASM *.ASM
  41.  
  42. 3) Compile SYSTEM: In \DELPHI\SOURCE\RTL\SYS type
  43.      DCC -cd -$d- -o\BP\RTL\LIB SYSTEM
  44.      
  45. 4) Start your TURBO.TPL: In \DELPHI\BIN type
  46.      DLIB TURBO.TPL +..\SOURCE\RTL\SYS\SYSTEM.TPU
  47.     
  48. Other files you may want to compile and include in TURBO.TPL:
  49.   unit      source can be found
  50.   OVERLAY   \BP\RTL\OVR
  51.   CRT       \BP\RTL\CRT
  52.   DOS       \BP\RTL\DOS (need to use TASM again)
  53.   PRINTER   \BP\RTL\PRT
  54.   STRINGS   \DELPHI\SOURCE\RTL70    (optional)
  55.   MEMORY    \BP\RTL\TV              (optional)
  56.   OBJECTS   \BP\RTL\COMMON          (optional)
  57. Compile the above files in the specified directory using DCC with the
  58. parameters -cd and -$d- to create "ver 8.0" .TPU files.  Then add the
  59. TPU files to TURBO.TPL as shown in step 4.
  60.  
  61. Now you're all set!  Use DCC with the "undocumented" -cd switch to create
  62. DOS EXEs with classes, exception handling, etc.
  63.  
  64.  
  65. -- DOS Protected Mode -----------------------------------------------------
  66.   Objective: create a TPP.TPL with units compiled under DELPHI
  67.  
  68. 1) Make sure the .OBJ files still exist from step 2 above.
  69.  
  70. 2) Create OBP from ASM: In \DELPHI\SOURCE\RTL\SYS type 
  71.      TASM -op -d_DPMI_ *.ASM *.OBP
  72.  
  73. 3) Compile SYSTEM: In \DELPHI\SOURCE\RTL\SYS type
  74.      DCC -cp -$d- -o\BP\RTL\LIB SYSTEM
  75.      
  76. 4) Start your TURBO.TPL: In \DELPHI\BIN type
  77.      DLIB TPP.TPL +..\SOURCE\RTL\SYS\SYSTEM.TPP
  78.  
  79. Other files you may want to compile and include in TPP.TPL:
  80.   unit      source can be found
  81.   CRT       \BP\RTL\CRT
  82.   DOS       \BP\RTL\DOS (TASM -op -d_DPMI_ *.ASM *.OBP)
  83.   PRINTER   \BP\RTL\PRT
  84.   STRINGS   \DELPHI\SOURCE\RTL70    
  85.   WINDOS    \DELPHI\SOURCE\RTL70
  86.   WINAPI    \DELPHI\SOURCE\RTL\WIN
  87.   MEMORY    \BP\RTL\TV              (optional)
  88.   OBJECTS   \BP\RTL\COMMON          (optional)
  89.   SYSUTILS  \DELPHI\SOURCE\RTL\SYS  (new, see below)
  90. Compile the above files in the specified directory using DCC with the
  91. parameters -cp and -$d- to create "ver 8.0" .TPP files.  Then add the
  92. TPP files to TPP.TPL as shown in step 4.
  93.  
  94.  
  95. -- SysUtils for DOS Protected Mode ----------------------------------------
  96. To get SYSUTILS to work properly in DOS PM you need to make a few minor
  97. changes to the source file (comes with VCL Source).  First make a backup
  98. of the SYSUTILS.PAS file and then I suggest puting "{$IFDEF WINDOWS}..." 
  99. around all of your changes.
  100.  
  101. 1) FileRead/FileWrite: RTM.EXE only supports _lread/write not _hread/write
  102.    and SysUtils needs to be updated to reflect that.  I will use FileRead
  103.    as the example:
  104.    In INTERFACE
  105.      {$IFDEF WINDOWS}
  106.      function FileRead(Handle: Integer; var Buffer; Count: Longint): Longint;
  107.      {$ELSE}
  108.      function FileRead(Handle: Integer; var Buffer; Count: Word): Word;
  109.      {$ENDIF}
  110.    In IMPLEMENTATION
  111.      function FileRead(Handle: Integer; var Buffer; Count: Word): Word;
  112.        external 'KERNEL' index 82; { _lread }
  113.    FileWrite needs the same changes and it has an external index of 86.
  114.  
  115. 2) Units used in the IMPLEMENTATION section:
  116.      {$IFDEF WINDOWS}
  117.      uses WinTypes, WinProcs, ToolHelp;
  118.      {$ELSE}
  119.      uses WinAPI;
  120.      {$ENDIF}
  121.  
  122. 3) Remove some exception (hardware, etc) handling.  Unfortunately RTM
  123.    does not support MakeProcInstance and FreeProcInstance otherwise 
  124.    none of the following would have to be removed.
  125.    A) in the INTERFACE section
  126.       {$IFDEF WINDOWS}
  127.       procedure EnableExceptionHandler(Enable: Boolean);
  128.       {$ENDIF}
  129.       
  130.    B) Around the procedure "GetModNameAndLogAddr" in the IMPLEMENTATION
  131.       section add {$IFDEF WINDOWS} and {$ENDIF}.
  132.  
  133.    C) In the procedure "ShowException":
  134.       var
  135.         .. existing definitions
  136.         Buffer: array[0..255] of Char;
  137.         {$IFDEF WINDOWS}
  138.         GlobalEntry: TGlobalEntry;
  139.         hMod: THandle;
  140.         {$ENDIF}
  141.       begin
  142.         {$IFDEF WINDOWS}
  143.         .. existing code
  144.         {$ENDIF}
  145.       end;
  146.    D) Before the procedure "ErrorHandler":
  147.       {$IFDEF WINDOWS}
  148.       const
  149.         Flags   = $10;
  150.         .. other consts
  151.             
  152.         Recurse: Word = 0;
  153.       {$ENDIF}
  154.    E) In the procedure "ErrorHandler":
  155.         1: E := OutOfMemory;
  156.         {$IFDEF WINDOWS}
  157.         2,4..10: with ExceptMap[ErrorCode] do E := EClass.CreateRes(EIdent);
  158.         3,11..16:
  159.         ..
  160.         end;
  161.         {$ELSE}
  162.         2..16: with ExceptMap[ErrorCode] do E := EClass.CreateRes(EIdent);
  163.         {$ENDIF}
  164.       else
  165.    F) Before the procedure "InterruptCallBack" add {$IFDEF WINDOWS} and
  166.       after the end of the procedure "EnableExceptionHandler" add {$ENDIF}.
  167.    G) In procedure "DoneExceptions" put IFDEF WINDOWS around the call to
  168.       EnableExceptionHandler.
  169.    H) In procedure "InitExceptions" put IFDEF WINDOWS around the assignment
  170.       "TaskID := GetCurrentTask;" and the call to EnableExceptionHandler.
  171.       
  172. 4) Add profile support provide in RTM.EXE.  After the comment 
  173.    "{ Initialization file support }" add the following:
  174.       {$IFNDEF WINDOWS}
  175.       function GetProfileInt( appName, keyName : pchar;
  176.         default : integer ) : word; far; external 'KERNEL' index 57;
  177.       function GetProfileString( appName, keyName, default, returned : pchar;
  178.         size : integer ) : integer; far; external 'KERNEL' index 58; 
  179.       {$ENDIF}                                                       
  180.                                                                     
  181. Compile SYSUTILS for DOS PM from the command line:
  182.   DCC -cp SYSUTILS
  183.   
  184. It is all set to add the TPP.TPL and use in your programs.  I have not 
  185. been able to test every function that is provided.  It would be diffucult
  186. to get SysUtils working for DOS Real Mode because of its use of resource
  187. files, although I am sure it is possible if someone would like to give it 
  188. a shot.  You could probably remove all the exception handling and get it
  189. to compile with BP7.
  190.  
  191.  
  192.  
  193. -- Classes for DOS Protected Mode -----------------------------------------
  194. Getting the CLASSES unit to compile for DOS PM is very simple compared to
  195. SYSUTILS.  
  196.  
  197. In the INTERFACE section change the uses clause:
  198.   {$IFDEF WINDOWS}
  199.   uses SysUtils, WinTypes, WinProcs;
  200.   {$ELSE}
  201.   uses SysUtils, WinAPI;
  202.   {$ENDIF}
  203.  
  204. You need to create a unit called CONSTS that has the following:
  205. (This information was obtained via the online browser because
  206. Borland does not proved CONSTS.PAS - don't ask me why not!?):
  207. ========================================
  208. unit Consts;
  209.  
  210. interface
  211.  
  212. const
  213.   SClassNotFound             = 61447;
  214.   SDuplicateClass            = 61457;
  215.   SRegisterError             = 61498;
  216.   SResNotFound               = 61449;
  217.   SLineTooLong               = 61459;
  218.   SReadError                 = 61443;
  219.   SWriteError                = 61444;
  220.   SInvalidImage              = 61448;
  221.   SFCreateError              = 61441;
  222.   SFOpenError                = 61442;
  223.   SMemoryStreamError         = 61445;
  224.   SInvalidProperty           = 61538;
  225.   SUnknownProperty           = 61462;
  226.   SPropertyException         = 61464;
  227.   SInvalidPropertyPath       = 61461;
  228.   SInvalidPropertyValue      = 61460;
  229.   SReadOnlyProperty          = 61463;
  230.   SCharExpected              = 61534;
  231.   SSymbolExpected            = 61535;
  232.   SParseError                = 61530;
  233.   SDuplicateName             = 61455;
  234.   SInvalidName               = 61456;
  235.   SListIndexError            = 61451;
  236.   SDuplicateString           = 61453;
  237.   SSortedListError           = 61452;
  238.   SIdentifierExpected        = 61531;
  239.   SStringExpected            = 61532;
  240.   SNumberExpected            = 61533;
  241.   SInvalidBinary             = 61539;
  242.   SInvalidString             = 61537;
  243.   SAssignError               = 61440;
  244.  
  245. implementation
  246.  
  247. end.
  248. ========================================
  249.  
  250. Now copy TYPINFO.INT to TYPINFO.PAS and copy the procedure/function 
  251. declarations from the INTERFACE to IMPLEMENTATION.  With each procedure and
  252. function add a "Begin End;".  Have each function return NIL, 0, etc 
  253. depending on its type.
  254.  
  255. Compile:
  256.   DCC -cp CLASSES
  257.  
  258. You can now use TList, TStrings, TStringList, TStream, etc in your DOS PM
  259. programs.  Because of changes to SysUtils THandleStream.Read/Write is
  260. limited to a buffer size of word and not longint.  You won't be able to
  261. use TReader and TWriter unless you can get Borland to give you the source
  262. or TPP for TYPINFO.PAS.
  263.